package com.cy;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 通过此案例演示rest请求的服务提供方的处理
 */
@RestController
@RequestMapping("/provider/template/")
public class RestProviderController演示Rest请求的增删改实现 {

    @Value("${spring.application.name}")
    private String server;

    //删除请求
    @DeleteMapping("{id}")
    public void doDelete(@PathVariable Integer id) {
        System.out.println(id + " 被" + server + "删除了");
    }

    //添加请求
    @PostMapping
    public Map<String, Object> doPost(@RequestBody Map<String, Object> map) {
        System.out.println("consumer post data: " + map);
        map.put("status", 1);
        map.put("server.port", server);
        return map;
    }

    //更新请求
    @PutMapping("{id}") //是由服务消费方传过来的 id=10
    public void doPut(@RequestBody Map<String, Object> map, @PathVariable Integer id) {
        System.out.println("consumer put data:" + map);
        System.out.println("id:" + id);
    }
}
